home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
commands
/
nroff
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-23
|
20KB
|
974 lines
#include "config.h"
/*
* main.c - main for nroff word processor
*
* similar to Unix(tm) nroff or RSX-11M RNO. adaptation of text processor
* given in "Software Tools", Kernighan and Plauger.
*
* adapted for atariST/TOS by Bill Rosenkranz 11/89
* net: rosenkra@hall.cray.com
* CIS: 71460,17
* GENIE: W.ROSENKRANZ
*
* original author:
*
* Stephen L. Browning
* 5723 North Parker Avenue
* Indianapolis, Indiana 46220
*
* history:
*
* - Originally written in BDS C;
* - Adapted for standard C by W. N. Paul
* - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
* - Changed array index i from type long to type int (32000 is the
* largest value anyhow) to prevent compiler warnings
* by Wim 'Blue Baron' van Dorst (wsincc@tuerc3.urc.tue.nl)
* - Changed termcap capabilities md/me, changed handling and
* removed the unused standout references
* by Wim 'Blue Baron' van Dorst (wsincc@tuerc3.urc.tue.nl)
*/
#define NRO_MAIN /* to define globals in nro.h */
#ifdef GEMDOS
#include <sys\types.h>
#include <sys\time.h>
#else
#include <sys/types.h>
#include <time.h>
#endif
#include <stdio.h>
#include "nroff.h"
main (argc, argv)
int argc;
char *argv[];
{
register int i;
int swflg;
int ifp = 0;
char *ptmp;
#ifndef GEMDOS
char *pterm;
char capability[100];
char *pcap;
char *ps;
#endif
/*
* set up initial flags and file descriptors
*/
swflg = FALSE;
ignoring = FALSE;
hold_screen = FALSE;
debugging = FALSE;
stepping = FALSE;
out_stream = stdout;
err_stream = stderr;
dbg_stream = stderr;
/*
* this is for tmp files, if ever needed. it SHOULD start
* out without the trailing slash. if not in env, use default
*/
if (ptmp = getenv ("TMPDIR"))
strcpy (tmpdir, ptmp);
else
strcpy (tmpdir, ".");
/*
* handle terminal for \fB, \fI
*/
#ifdef GEMDOS
/*
* atari/TOS is easy...
*/
strcpy (s_bold, "\33p");
strcpy (e_bold, "\33q");
strcpy (s_italic, "\33p");
strcpy (e_italic, "\33q");
#else
s_italic[0] = '\0';
e_italic[0] = '\0';
s_bold[0] = '\0';
e_bold[0] = '\0';
if ((pterm = getenv ("TERM"))
&& (tgetent (termcap, pterm) == 1))
{
/*
* termcap capabilities md/me for bold, us/ue for italic,
* so/se if all else fails
*/
pcap = capability;
if (ps = tgetstr ("so", &pcap))
{
/* NOTE: the termcap on my sun has padding or something in it so i just
arbitarily remove it here. this is not right, but the worst that happens
is you have no standout. since minix uses standard ansi escape for so,
\E[7m, this should not be a problem. also i rarely use any non-ansi
terminals so this is also not a problem for me. the right thing to do
would be to use tputs() to remove the padding and write a new string
but i am lazy... */
while (*ps && *ps != 0x1B) ps++;
strcpy (s_italic, ps);
strcpy (s_bold, ps);
}
if (ps = tgetstr ("se", &pcap))
{
while (*ps && *ps != 0x1B) ps++;
strcpy (e_italic, ps);
strcpy (e_bold, ps);
}
/*
* Because the type faces are actually exclusive and
* the terminal capabilities are not the one has turn
* the other off before starting itself
*/
/* End Italic */
if (ps = tgetstr ("ue", &pcap))
{
while (*ps && *ps != 0x1B) ps++;
strcpy (e_italic, ps);
}
/* End Bold */
if (ps = tgetstr ("me", &pcap))
{
while (*ps && *ps != 0x1B) ps++;
strcpy (e_bold, ps);
}
/* Start Italic */
if (ps = tgetstr ("us", &pcap))
{
while (*ps && *ps != 0x1B) ps++;
strcpy (s_italic, e_bold);
strcat (s_italic, ps);
}
/* Start Bold */
if (ps = tgetstr ("md", &pcap))
{
while (*ps && *ps != 0x1B) ps++;
strcpy (s_bold, e_italic);
strcat (s_bold, ps);
}
}
#endif
/*
* initialize structures (defaults)
*/
init ();
/*
* parse cmdline flags
*/
for (i = 1; i < argc; ++i)
{
if (*argv[i] == '-' || *argv[i] == '+')
{
if (pswitch (argv[i], argv[i+1], &swflg) == ERR)
err_exit (-1);
}
}
/*
* loop on files
*/
for (i = 1; i < argc; ++i)
{
if (*argv[i] != '-' && *argv[i] != '+')
{
/*
* open this file...
*/
if ((sofile[0] = fopen (argv[i], "r")) == NULL_FPTR)
{
fprintf (err_stream,
"***%s: unable to open file %s\n",
myname, argv[i]);
err_exit (-1);
}
else
{
/*
* do it for this file...
*/
ifp = 1;
profile ();
fclose (sofile[0]);
}
}
else if (*argv[i] == '-' && *(argv[i]+1) == 0)
{
/*
* - means read stdin (anywhere in file list)
*/
sofile[0] = stdin;
ifp = 1;
profile ();
}
}
/*
* if no files, usage (should really use stdin...)
*/
if ((ifp == 0 && swflg == FALSE) || argc <= 1)
{
usage ();
err_exit (-1);
}
/*
* normal exit. this will fflush/fclose streams...
*/
err_exit (0);
}
/*------------------------------*/
/* usage */
/*------------------------------*/
usage ()
{
/*
* note: -l may not work correctly
*/
fprintf (stderr, "Usage: %s [options] file [...]\n", myname);
fprintf (stderr, "Options: -a no font changes\n");
fprintf (stderr, " -b backspace\n");
fprintf (stderr, " -d debug mode (file: nroff.dbg)\n");
#ifdef GEMDOS
fprintf (stderr, " -h hold screen before desktop\n");
#endif
fprintf (stderr, " -l output to printer\n");
fprintf (stderr, " -m<name> macro file (e.g. -man)\n");
fprintf (stderr, " -o file error log file (stderr is default)\n");
fprintf (stderr, " -pl<n> page length\n");
fprintf (stderr, " -po<n> page offset\n");
fprintf (stderr, " -pn<n> initial page number\n");
fprintf (stderr, " -s step through pages\n");
fprintf (stderr, " -v print version only\n");
fprintf (stderr, " +<n> first page to do\n");
fprintf (stderr, " -<n> last page to do\n");
fprintf (stderr, " - use stdin (in file list)\n");
}
/*------------------------------*/
/* init */
/*------------------------------*/
init ()
{
/*
* initialize parameters for nro word processor
*/
register int i;
time_t tval;
char *ctim;
tval = time (0L);
dc.fill = YES;
dc.dofnt = YES;
dc.lsval = 1;
dc.inval = 0;
dc.rmval = PAGEWIDTH - 1;
dc.llval = PAGEWIDTH - 1;
dc.ltval = PAGEWIDTH - 1;
dc.tival = 0;
dc.ceval = 0;
dc.ulval = 0;
dc.cuval = 0;
dc.juval = YES;
dc.adjval = ADJ_BOTH;
dc.boval = 0;
dc.bsflg = FALSE;
dc.prflg = TRUE;
dc.sprdir = 0;
dc.flevel = 0;
dc.lastfnt = 1;
dc.thisfnt = 1;
dc.escon = YES;
dc.pgchr = '%';
dc.cmdchr = '.';
dc.escchr = '\\';
dc.nobrchr = '\'';
for (i = 0; i < 26; ++i)
dc.nr[i] = 0;
for (i = 0; i < 26; ++i)
dc.nrauto[i] = 1;
for (i = 0; i < 26; ++i)
dc.nrfmt[i] = '1';
/*
* initialize internal regs. first zero out...
*/
for (i = 0; i < MAXREGS; i++)
{
rg[i].rname[0] = rg[i].rname[1] = rg[i].rname[2] = rg[i].rname[3] = '\0';
rg[i].rauto = 1;
rg[i].rval = 0;
rg[i].rflag = RF_READ;
rg[i].rfmt = '1';
}
/*
* this should be checked...
*/
ctim = ctime (&tval);
/*
* predefined regs. these are read/write:
*/
i = 0;
strcpy (rg[i].rname, "%"); /* current page */
rg[i].rauto = 1;
rg[i].rval = 0;
rg[i].rflag = RF_READ | RF_WRITE;
rg[i].rfmt = '1';
i++;
strcpy (rg[i].rname, "ct"); /* character type */
rg[i].rauto = 1;
rg[i].rval = 0;
rg[i].rflag = RF_READ | RF_WRITE;
rg[i].rfmt = '1';
i++;
strcpy (rg[i].rname, "dl"); /* width of last complete di */
rg[i].rauto = 1;
rg[i].rval = 0;
rg[i].rflag = RF_READ | RF_WRITE;
rg[i].rfmt = '1';
i++;
strcpy (rg[i].rname, "dn"); /* height of last complete di */
rg[i].rauto = 1;
rg[i].rval = 0;
rg[i].rflag = RF_READ | RF_WRITE;
rg[i].rfmt = '1';
i++;
strcpy (rg[i].rname, "dw"); /* day of week (1-7) */
rg[i].rval = 0;
if (!strncmp (&ctim[0], "Sun", 3))
rg[i].rval = 1;
else if (!strncmp (&ctim[0], "Mon", 3))
rg[i].rval = 2;
else if (!strncmp (&ctim[0], "Tue", 3))
rg[i].rval = 3;
else if (!str